/*
 * @Author: zi.yang
 * @Date: 2022-11-27 20:01:35
 * @LastEditors: zi.yang
 * @LastEditTime: 2022-12-03 16:00:33
 * @Description: Mock Async Data
 * @FilePath: /promise/mock/index.js
 */
const random = () => Math.random();
module.exports = {
  fetchUserInfo(callback) {
    const timeId = setTimeout(() => {
      if (random() > 0.6) {
        callback({ success: false, error: 'fetchUserInfo error' });
      } else {
        callback({ success: true, username: 'zi.yang', age: 18 });
      }
      clearTimeout(timeId);
    }, 600);
  },
  fetchUserArticle(callback) {
    const timeId = setTimeout(() => {
      if (random() > 0.6) {
        callback({ success: false, error: 'fetchUserArticle error' });
      } else {
        callback({ success: true, title: '论心不论迹', liked: 1000 });
      }
      clearTimeout(timeId);
    }, 800);
  },
};
